#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <unordered_map>
#include "log.hpp"
using namespace std;
const std::string unknown = "unknown";
const std::string mydict = "./recource/dict.txt";
const std::string sep = " ";
class word
{
    ;
};
class TranSlate
{
public:
TranSlate( string dict_path=mydict):_dict_path(dict_path)
{
        LoadDict();
        Parse();
}
void LoadDict()
{
 ifstream in(_dict_path);
 string line;
 while(getline(in,line))

{
    lines.push_back(line);
}
in.close();
lg.massage(Debug, "Load dict txt success, path: %s\n", _dict_path.c_str());
}
void Parse()
{
for(auto line:lines)
{
 auto pos=line.find(sep);
 if(pos == std::string::npos) continue;
 else
 {
 string word=line.substr(0,pos);
 string chinese=line.substr(pos+sep.size());
 _dict.insert(make_pair(word,chinese));
 }
  lg.massage(Debug, "Parse dict txt success, path: %s\n", _dict_path.c_str());
}
}
std::string Excute(const std::string &word)
    {
        auto iter = _dict.find(word);
        if (iter == _dict.end())
            return unknown;
        else
            return _dict[word];
    }
~TranSlate()
{

}
private:
 std::string _dict_path;
    std::unordered_map<std::string, std::string> _dict;
    std::vector<std::string> lines;
};
